package main

import "fmt"

func main() {
	strs := []string{"eat", "tea", "tan", "ate", "nat", "bat"}
	v := groupAnagrams(strs)
	fmt.Println(v)
}

func groupAnagrams(strs []string) [][]string {
	resMap := map[[26]int][]string{}
	for _, str := range strs {
		h := hash(str)
		resMap[h] = append(resMap[h], str)
	}
	res := [][]string{}
	for _, item := range resMap {
		res = append(res, item)
	}
	return res
}

func hash(str string) [26]int {
	cnt := [26]int{}
	for _, b := range str {
		cnt[b-'a']++
	}
	return cnt
}
